# 作者:MRHyy
# 2025年02月20日20时51分34秒
# 1.多个缺省参数的传递
def parameter_info(name, gender=True):
    gender_text = 'man'
    if not gender:
        gender_text = 'woman'
    print("%s is %s " % (name, gender_text))


parameter_info('xiaoming')
parameter_info('xiaoming', False)
parameter_info('xiaoming', True)


def parameter_info1(name, tile='', gender=True):
    gender_text = 'man'
    if not gender:
        gender_text = 'woman'
    print("%s %s is %s " % (tile, name, gender_text))


parameter_info1('xiaoming')
parameter_info1('xiaoming', 'master', False)
parameter_info1('xiaoming', gender=True)


# 2.多值参数练习，元组，字典的传参拆包练习
def main(num, num1, *args, **kwargs):
    print(num)

    print(args)
    print(kwargs)


def demo(num, *args, **kwargs):
    main(num, *args, **kwargs)


demo(1, 2, name='xiaoming', age='1')
demo(1, 2, 3, 4, )
demo(1, 5)


# 3.设计一个类，实例化1个对象，会实现下面两种行为（和上课保持一致即可）
# 需一只 黄颜色 的 狗狗 叫 小黄
# 具有  汪汪叫 行为
# 具有  摇尾巴 行为
class Dog:
    def __init__(self, name, color):
        self.name = name
        self.color = color
        print("i am a %s dog called %s " % (self.color, self.name))

    def bark(self):
        print('i can bark')

    def shake(self):
        print('i can shake')


if __name__ == '__main__':
    xiaohuang = Dog('xiaohuang', color='yellow')
    xiaohuang.bark()
    xiaohuang.shake()


#4、练习封装案例       (家具城)
class HouseItem:
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return "%s 占地 %.2f " % (self.name, self.area)


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.item_list = []

    def add_item(self, item: HouseItem):
        print(f'add item :{item}')
        if self.free_area > item.area:
            self.item_list.append(item.name)
            self.free_area -= item.area
        else:
            print("this room is not enougth to adopt this item")

    def __str__(self):

        return "户型：%s \n总面积：%.2f[remain：%.2f] \n家具：%s" % (
            self.house_type, self.free_area, self.area, self.item_list)


bed = HouseItem('water bed', 5)
chair = HouseItem('chair', 20)
print(bed)
print(chair)
house = House("10室10厅", 5000)
house.add_item(bed)
house.add_item(chair)
print(house)


# 5.私有属性和私有方法
class stu:
    def __init__(self, name, bookname):
        self.name = name
        self.__bookname = bookname

    def __secret(self):
        print(self.__bookname)

    def teacher(self):
        self.__secret()


if __name__ == '__main__':
    otherstu = stu('zh3', 'math')
    otherstu.teacher()


# 6.单继承，多重继承案例
class Animal:
    def eat(self):
        print('eat')

    def drink(self):
        print('drink')

    def speak(self):
        print('speak')


class Dog(Animal):
    def shake(self):
        print('shake')


class cat(Animal):
    def bark(self):
        print('bark')


class GunDog(Dog):
    def shoot(self):
        print('shoot')

    def shake(self):
        super().shake()
        print('i can shootshake')


if __name__ == '__main__':
    xiaohuang = Dog()
    xiaohuang.shake()
    huanggou = GunDog()
    huanggou.shake()


class A:
    def test(self):
        print('A.test()')


class B:
    def test(self):
        print('B.test()')

    def test_1(self):
        print('B.test()')


class C(A, B):
    def test(self):
        super().test()
        print('C.test()')


if __name__ == '__main__':
    c = C()
    c.test()
    print(C.__mro__)
    c.test_1()

# 7.单例模式
class MusicPlayer(object):

    A = None

    def __new__(cls, *args, **kwargs):
        if cls.A is None:
            cls.A = super().__new__(cls)

        return cls.A


    def __init__(self, music_name):
        print(f'播放器初始化{music_name}')
        self.music_name = music_name

if __name__ == '__main__':
    player1 = MusicPlayer('1')
    player2 = MusicPlayer('2')
    print(id(player1))
    print(id(player2))